package com.ruoyi.hospital.registered.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hospital.registered.domain.TRegistered;
import com.ruoyi.hospital.registered.service.ITRegisteredService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 门诊挂号Controller
 *
 * @author Shawn
 * @date 2024-02-21
 */
@Controller
@RequestMapping("/hospital/registered")
public class TRegisteredController extends BaseController {
    private String prefix = "hospital/registered";

    @Autowired
    private ITRegisteredService tRegisteredService;

    @GetMapping()
    public String registered() {
        return prefix + "/registered";
    }

    /**
     * 查询门诊挂号列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TRegistered tRegistered) {
        startPage();
        List<TRegistered> list = tRegisteredService.selectTRegisteredList(tRegistered);
        return getDataTable(list);
    }


    @PostMapping("/list/admission")
    @ResponseBody
    public TableDataInfo listAdmission(TRegistered tRegistered) {
        startPage();
        tRegistered.setFinish(0l);
        List<TRegistered> list = tRegisteredService.selectTRegisteredList(tRegistered);
        return getDataTable(list);
    }


    /**
     * 导出门诊挂号列表
     */
    @RequiresPermissions("hospital:registered:export")
    @Log(title = "门诊挂号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TRegistered tRegistered) {
        List<TRegistered> list = tRegisteredService.selectTRegisteredList(tRegistered);
        ExcelUtil<TRegistered> util = new ExcelUtil<TRegistered>(TRegistered.class);
        return util.exportExcel(list, "门诊挂号数据");
    }

    /**
     * 新增门诊挂号
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存门诊挂号
     */
    @RequiresPermissions("hospital:registered:add")
    @Log(title = "门诊挂号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TRegistered tRegistered) {
        return toAjax(tRegisteredService.insertTRegistered(tRegistered));
    }

    /**
     * 修改门诊挂号
     */
    @RequiresPermissions("hospital:registered:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        TRegistered tRegistered = tRegisteredService.selectTRegisteredById(id);
        mmap.put("tRegistered", tRegistered);
        return prefix + "/edit";
    }

    /**
     * 修改保存门诊挂号
     */
    @RequiresPermissions("hospital:registered:edit")
    @Log(title = "门诊挂号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TRegistered tRegistered) {
        return toAjax(tRegisteredService.updateTRegistered(tRegistered));
    }

    /**
     * 删除门诊挂号
     */
    @RequiresPermissions("hospital:registered:remove")
    @Log(title = "门诊挂号", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tRegisteredService.deleteTRegisteredByIds(ids));
    }
}
